<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link rel="stylesheet" href="feuilledestyle.css">
        <link rel="stylesheet" href="menuHead/jquery.cleditor.css">
        <link href="menu2/styles.css" rel="stylesheet" type="text/css">
        <script src="cryptMD5.js" type="text/javascript"></script><!--mce:1-->
        <script type="text/javascript"> 
        
        
        function verifMDP()
        {
            /*var mdpAct=(document.getElementsByTagName('input'))[0];
            mdpA=mdpAct.value;
            
            var mdpSais=(document.getElementsByTagName('input'))[1];
            mdpS=mdpSais.value;
            
            if(mdpA==mdpS)
                {
                    mdpSais.setAttribute("style", "border:2px green solid;");
                    ajoutBt();
                    //res.innerHTML="<font color='lime'>Correct</font>";
                }else
                    {
                        mdpSais.setAttribute("style", "border:2px red solid;");
                        ajoutBt();
                        //res.innerHTML="<font color='red'>incorrect</font>";
                    }*/
                    
                    
                    //var mdpSais=(document.getElementsByTagName('input'))[1];
            //var mdpS=< ?php echo $m=motP();?>
            //alert ('mdpS');
            
            /*if(mdpA==mdpS)
                {
                    mdpSais.setAttribute("style", "border:2px green solid;");
                    ajoutBt();
                    //res.innerHTML="<font color='lime'>Correct</font>";
                }else
                    {
                        mdpSais.setAttribute("style", "border:2px red solid;");
                        ajoutBt();
                        //res.innerHTML="<font color='red'>incorrect</font>";
                    }*/
                    
                    
                    
                    
        }
        
        function loginValidation(){
            
            //Récupération du mot de passe
            var passe = document.getElementById('passeSaisie').value;
           
            //Remise a zéro du mot de passe
            document.getElementById('passeSaisie').value = "";
            //Cryptage du mot de passe en MD5 à l'aide de la fonction MD5()
            //présente dans le fichier cryptMD5.js
            var cenvertMp = MD5(passe);
            
            //Ecriture du mot de passe dans le champ md5
            document.getElementById('md5').value = cenvertMp;
            //Envoi du formulaire
            document.submit();
        }
        
        
        function verifMCM()
        {
            var mdpAct=(document.getElementsByTagName('input'))[3];
            mdpA=mdpAct.value;
            var mdpSais=(document.getElementsByTagName('input'))[4];
            mdpS=mdpSais.value;
            
            if(mdpS!="")
                {
                    if(mdpA==mdpS)
                        {
                            mdpSais.setAttribute("style", "border:2px green solid;");
                            ajoutBt();
                        }else if(mdpA!=mdpS)
                            {
                                mdpSais.setAttribute("style", "border:2px red solid;");
                                ajoutBt();
                                alert('Mots de passe non identiques');
                            }
                }
        }
        
        
        function verifNbC()
        {
            var mdpAct=(document.getElementsByTagName('input'))[3];
            var mdpA=mdpAct.value;
           
            var reg=/([A-z]|[0-9]){6,12}/;
            if(reg.test(mdpA))
                {
                    mdpAct.setAttribute("style", "border:2px green solid;");
                    ajoutBt();
                }else
                    {
                        mdpAct.setAttribute("style", "border:2px red solid;");
                        ajoutBt();
                        alert('Mot de passe doit comprendre entre 6 et 12 caractères');
                    }
        }
        
        
        function ajoutBt()
        {
            
            for(var i=3;i<5;i++)
                {
                    var mdpS=(document.getElementsByTagName('input'))[i];
                    var rep=mdpS.getAttribute("style");
                    if(rep=='border:2px green solid;')
                        {
                            if(i==4)
                                {
                                    var btEnr=document.getElementById("btEnr");
                                    btEnr.innerHTML ='<input type="submit" name="" value="Enregistrer">';
                                }else
                                     {
                                          var btEnr=document.getElementById("btEnr");
                                          btEnr.innerHTML ='';
                                     }
                        }
                }
            
        }
        
        </script>
        
        <script type="text/javascript"  src="verifModifInfo.js"></script>
    </head>
    <body vlink="blue">
     <div id="page">
        <?php 
        include 'header.php';
        include 'editInfo.php';
        require_once 'connexion (2).php'; 
        include 'menu.php';
        ?>
         
        <?php
        $mess= '';
        
        if(isset($_SESSION['mail']))
        {
            $mail=$_SESSION['mail'];
        }
         
        if(isset($_POST['md5'])&& $_POST['md5'] <> ""){
            
                    $reqPers="select * from personne where MAILPERSONNE='".$mail."'";
                    $resuPers=$connexion->query($reqPers);

                    if($lectPers=$resuPers->fetch(PDO::FETCH_ASSOC))
                    {
                            $motP=$lectPers['MOTDEPASSE'];
                    }

                    if($motP==$_POST['md5'])
                    {
                           $reqPers="update personne set MOTDEPASSE = '".md5($_POST['nouvPasse'])."' where MAILPERSONNE='".$mail."'";
                           $resuPers=$connexion->query($reqPers);

                           $mess=  '<script type="text/javascript"> 
                                alert("Votre mot de passe a été changé");</script>';
                    }  else {
                                $mess= '<script type="text/javascript"> 
                                        alert("Erreur dans la saisie de l\'ancien mot de passe'.$_POST['md5'].');</script>';
                            }
        }
        
        ?>   
         
         
        <div id="cadre">
        <FORM style="float:left; margin-top: 20px; background-color: orange; "> <INPUT TYPE="button" VALUE="Retour" onClick="history.back()"> </FORM> 
          <?php 
       
          $choix=null;
          if(isset($_GET['choix']))
          {
              $choix=$_GET['choix'];
          }else{
              
              $choix="vide";
          
               }
          $info=null;  
          if(isset($_GET['info']))
          {
              $info=$_GET['info'];
          }else{
              
              $info="";
          
               }
          $pass=null; 
          if(isset($_GET['pass']))
          {
              $pass=$_GET['pass'];
          }else{
              
              $pass="";
          
               }
                $societe=null; 
          if(isset($_GET['societe']))
          {
              $societe=$_GET['societe'];
          }else{
              
              $societe="";
          
               }
               
               
               echo '<div class="centre">';  
                if(($info==null)&&($pass==null)&&($societe==null))
               {
               ?>
          
               <br><div class="centre"> 
             <table class="petitformMenu" align="center" >
                <tr>
                    <td><a href='coordonne.php?info=info&choix=<?php echo $choix;?>'><span>Modifier mes informations personnelles</span></a></td>
                </tr>
                <tr>
                    <td><a href='coordonne.php?pass=pass&choix=<?php echo $choix;?>'><span>Modifier mon mot de passe</span></a></td>
                </tr>
            </table>
            </div>
               <?php
               }else{
           
               
               if($choix=="admin")
               {if($info!=null)
                    {
               ?>
              <br><div class="centre"> 
                   <form action="updateCoord.php?user=admin" name="info" method="POST">
                <table class="petitformdata" align="center" >
                <tr>
                    <td><span>Nom : </span></td><td><input type="text" name="nomp" id="nomp" onblur="Admin();" value="<?php echo $nomp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Prénom : </span></td><td><input type="text" name="prenomp" id="prenomp" onblur="Admin();" value="<?php echo $prenomp ?>"></td>
                </tr>
                <tr>
                    <td><span>Mail : </span></td><td><input type="text" name="mailp" id="mailp" onblur="Admin()" value="<?php echo $mailp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Téléphone : </span></td><td><input type="text" name="telp" id="telp" onblur="Admin();" value="<?php echo $telp; ?>" maxlength="10"></td>
                </tr>
                 <tr>
                    <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
                </table>
                </form>
                 </div>
                <?php 
               }else if($pass!=null)
               {
          ?>
                 <br><div class="centre">
             <form action='coordonne.php?pass=pass&choix=<?php echo $choix;?>' name="passe" method="POST" onsubmit="loginValidation()">
                <table class="petitformdata" align="center" >     
                <tr>
                    <td>
                        <span>Mot de passe actuel : </span>
                    </td>
                    <td>
                       <input type="password" id="passeSaisie" name="passeSaisie" value="" >
                       <input id="md5" name="md5" type="hidden" />
                    </td>
                </tr><tr>
                    <td>
                    </td> 
                    <td>
                        <?php echo $mess; ?>
                    </td>
                </tr>
                <tr>
                    <td><span>Nouveau mot de passe</span></td><td><input type="password" name="nouvPasse" value="" onblur="verifNbC()"></td>
                </tr>
                <tr>
                    <td><span>Comfirmez le mot de passe</span></td><td><input type="password" name="comfirmPasse" value="" onblur="verifMCM()"></td>
                </tr>
                 <tr>
                    <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
                </table>
                </form>
           </div>
          <?php
          
          }  }else if($choix=="professeur")
               {if($info!=null)
                    {
               ?>
              <br><div class="centre"> 
                <form action="updateCoord.php?user=professeur" name="info" method="POST">
                <table class="petitformdata" align="center" >
                <tr>
                    <td><span>Nom : </span></td><td><input type="text" name="nomp" id="nomp" onblur="Prof();" value="<?php echo $nomp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Prénom : </span></td><td><input type="text" name="prenomp" id="prenomp" onblur="Prof();" value="<?php echo $prenomp ?>"></td>
                </tr>
                <tr>
                    <td><span>Mail : </span></td><td><input type="text" name="mailp" id="mailp" onblur="Prof();" value="<?php echo $mailp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Téléphone : </span></td><td><input type="text" name="telp" id="telp" onblur="Prof();" value="<?php echo $telp; ?>" maxlength="10"></td>
                </tr>
                 <tr>
                    <td><span>Matière : </span></td><td><input type="text" name="matiere" id="matiere" onblur="Prof();" value=""></td>
                </tr>
                <tr>
                    <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
                </table>
                </form>
                 </div>
                <?php 
               }else if($pass!=null)
               {
          ?>
                <br><div class="centre">
             <form action='coordonne.php?pass=pass&choix=<?php echo $choix;?>' name="passe" method="POST" onsubmit="loginValidation()">
                <table class="petitformdata" align="center" >     
                <tr>
                    <td>
                        <span>Mot de passe actuel : </span>
                    </td>
                    <td>
                       <input type="password" id="passeSaisie" name="passeSaisie" value="" >
                       <input id="md5" name="md5" type="hidden" />
                    </td>
                </tr><tr>
                    <td>
                    </td> 
                    <td>
                        <?php echo $mess; ?>
                    </td>
                </tr>
                <tr>
                    <td><span>Nouveau mot de passe</span></td><td><input type="password" name="nouvPasse" value="" onblur="verifNbC()"></td>
                </tr>
                <tr>
                    <td><span>Comfirmez le mot de passe</span></td><td><input type="password" name="comfimPasse" value="" onblur="verifMCM()"></td>
                </tr>
                 <tr>
                     <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
            </table>
            </form>
           </div>
          <?php
          
          } }else if($choix=="eleve")
               {if($info!=null)
                    {
               ?>
              <br><div class="centre"> 
                <form action="updateCoord.php?user=eleve" name="info" method="POST">
                <table class="petitformdata" align="center" >
                <tr>
                    <td><span>Nom : </span></td><td><input type="text" name="nomp" id="nomp" onblur="Eleve();" value="<?php echo $nomp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Prénom : </span></td><td><input type="text" name="prenomp" id="prenomp" onblur="Eleve();" value="<?php echo $prenomp ?>"></td>
                </tr>
                <tr>
                    <td><span>Mail : </span></td><td><input type="text" name="mailp" id="mailp" onblur="Eleve();" value="<?php echo $mailp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Téléphone : </span></td><td><input type="text" name="telp" id="telp" onblur="Eleve();" value="<?php echo $telp; ?>" maxlength="10"></td>
                </tr>
                 <tr>
                    <td><span>Date de N. : </span></td><td><input type="text" name="dateNE" id="dateNE" onblur="Eleve();" value="" maxlength="10"></td>
                </tr>
                 <tr>
                    <td><span>Adresse : </span></td><td><input type="text" name="adrE" id="adrE" onblur="Eleve();" value="" maxlenght="100"></td>
                </tr>
                <tr>
                    <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
                </table>
                </form>
                 </div>
                <?php 
               }else if($pass!=null)
               {
          ?>
                 <br><div class="centre">
             <form action='coordonne.php?pass=pass&choix=<?php echo $choix;?>' name="passe" method="POST" onsubmit="loginValidation()">
                <table class="petitformdata" align="center" >     
                <tr>
                    <td>
                        <span>Mot de passe actuel : </span>
                    </td>
                    <td>
                       <input type="password" id="passeSaisie" name="passeSaisie" value="" >
                       <input id="md5" name="md5" type="hidden" />
                    </td>
                </tr><tr>
                    <td>
                    </td> 
                    <td>
                        <?php echo $mess; ?>
                    </td>
                </tr>
                <tr>
                    <td><span>Nouveau mot de passe</span></td><td><input type="password" name="nouvPasse" value="" onblur="verifNbC()"></td>
                </tr>
                <tr>
                    <td><span>Comfirmez le mot de passe</span></td><td><input type="password" name="comfirmPasse" value="" onblur="verifMCM()"></td>
                </tr>
                 <tr>
                     <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
            </table>
            </form>
           </div>
          <?php
          
          } 
               }else if($choix=="maitrestage")
               {  
                   if(($societe==null)&&($pass==null)&&($info!=null))
                    {
                       include 'editInfo.php';
               ?>
                <br><div class="centre"> 
                   
                <form action="updateCoord.php?user=maitrestage" name="info" method="POST">
                <table class="petitformdata" align="center" >
                <tr>
                    <td><span>Nom : </span></td><td><input type="text" name="nomp" id="nomp" onblur="Maitre();" value="<?php echo $nomp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Prénom : </span></td><td><input type="text" name="prenomp" id="prenomp" onblur="Maitre();" value="<?php echo $prenomp ?>"></td>
                </tr>
                <tr>
                    <td><span>Mail : </span></td><td><input type="text" name="mailp" id="mailp" onblur="Maitre()" value="<?php echo $mailp; ?>"></td>
                </tr>
                <tr>
                    <td><span>Téléphone : </span></td><td><input type="text" name="telp" id="telp" onblur="Maitre();" value="<?php echo $telp; ?>" maxlength="10"></td>
                </tr>
                <tr>
                    <td><span>Fonction dans la société : </span></td><td><input type="text" name="fonctionM" id="fonctionM" onblur="Maitre();" value="<?php echo $fonctionM; ?>"></td>
                </tr>
                <tr>
                    <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
                </table>
                </form>
                </div>
                <?php 
               }else  if(($societe==null)&&($pass!=null)&&($info==null))
               {  
          ?>
                 <br><div class="centre">
             <form action='coordonne.php?pass=pass&choix=<?php echo $choix;?>' name="passe" method="POST" onsubmit="loginValidation()">
                <table class="petitformdata" align="center" >     
                <tr>
                    <td>
                        <span>Mot de passe actuel : </span>
                    </td>
                    <td>
                       <input type="text" id="passeSaisie" name="passeSaisie" value="" >
                       <input id="md5" name="md5" type="hidden" />
                    </td>
                </tr><tr>
                    <td>
                    </td> 
                    <td>
                        <?php echo $mess; ?>
                    </td>
                </tr>
                <tr>
                    <td><span>Nouveau mot de passe</span></td><td><input type="password" name="nouvPasse" value="" onblur="verifNbC()"></td>
                </tr>
                <tr>
                    <td><span>Comfirmez le mot de passe</span></td><td><input type="password" name="comfirmPasse" value="" onblur="verifMCM()"></td>
                </tr>
                 <tr>
                     <td><span><a href="coordonne.php?choix=<?php echo $choix;?>"><input type="button" value="Annuler"></a></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
            </table>
            </form>
           </div>
          <?php
          
          } else if(($societe!=null)&&($pass==null)&&($info==null))
               {  include 'editInfo.php';
          ?>
                 <br><div class="centre"> 
               <form action="updateCoord.php?user=maitrestage&soc=true" name="info" method="POST">
                <table class="petitformdata" align="center" >     
                <tr>
                    <td><span>Nom Soc. : </span></td><td><input type="text" name="nomS" id="nomS" onblur="Entreprise()" value="<?php echo $nomS; ?>"></td>
                </tr>
                <tr>
                    <td><span>Adresse Soc. : </span></td><td><input type="text" name="adrS" id="adrS" onblur="Entreprise()" value="<?php echo $adrS; ?>"></td>
                </tr>
                <tr>
                    <td><span>Mail Soc. : </span></td><td><input type="email" name="mailS" id="mailS" onblur="Entreprise()" value="<?php echo $mailS; ?>"></td>
                </tr>
                <tr>
                    <td><span>Téléphone Soc. : </span></td><td><input type="text" name="telS" id="telS" onblur="Entreprise()" value="<?php echo $telS; ?>"></td>
                </tr>
                <tr>
                    <td><span>Description Soc. : </span></td><td><textarea name="descS" id="descS" onblur="Entreprise()" cols="15" rows="3" Maxlength="255"><?php echo $descS; ?></textarea></td>
                </tr>
                <tr>
                    <td><span>Site web Soc. : </span></td><td><input type="text" name="siteS" value="<?php echo $siteS; ?>"></td>
                </tr>
                <tr>
                     <td><span><input type="button" value="Annuler" onclick="history.back()"></span></td><td><h5 id="btEnr"></h5></td>
                </tr>
            </table>
           </form>
           </div>
          <?php
          
          } 
               }else if($choix=="vide")
               {
          ?>
           <br><div class="centre"> 
            <table class="petitformMenu" align="center" >
                <tr>
                    <td>
                       <h3>Vous devez vous connecter à l'accueil pour pouvoir naviguer dans le site.</h3>
                    </td>
                </tr>
            </table>
           </div>
          <?php 
               }
               }
          
          ?>
            </div>
	
            </div> 
                <?php require_once 'pied.php';?>
         </div>
    </body>
</html>